package com.cskaoyan.mall.pay.exception;

import com.cskaoyan.mall.commons.result.ServiceCallResponse;
import com.cskaoyan.mall.commons.result.ServiceCallResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理、数据预处理等
 */
//@ControllerAdvice(basePackages = "com.cskaoyan.order.api")
public class ServiceCallExceptionHandler {

    private static final Logger LOG = LoggerFactory.getLogger(ServiceCallExceptionHandler.class);

    /**
     * 所有异常统一处理
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ServiceCallResponse exceptionHandler(Exception e) {
        LOG.error("服务调用异常：", e);
        return new ServiceCallResponseUtil().ok(e.getMessage());
    }

}
